/*
 * GuildFraktionInfo - list the reputation and the guild level of all members of a wow guild
 * Copyright (C) [2012 - 2013] [www.marantis.de]
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public 
 * License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later 
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program; if not, 
 * see <http://www.gnu.org/licenses/>.
 */
package de.marantis.app.wow.gfi.helper;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;

public class ReputationEnumTypeSerializer implements JsonSerializer<Enum<?>> {

    private static final JsonParser mParser = new JsonParser();

    @Override
    public JsonElement serialize(Enum<?> t, Type type, JsonSerializationContext jsc) {

        if (!(t instanceof ReputationEnum)) {
            throw new IllegalArgumentException(type.toString() + " is no ReputationEnum!");
        }

        ReputationEnum repEnum = (ReputationEnum) t;
        String s = String.valueOf(repEnum.getRep());
        return mParser.parse(s);
    }
}
